import { createApp } from 'vue';
import './style.css';
import App from "./App.vue";
import {createRouter, createWebHistory} from "vue-router";
import Home from "./components/Home.vue";
import About from "./components/About.vue";
import Admin from "./components/Admin.vue";
import Addvideo from "./components/admin/addvideo.vue";
import ChangeUserInfo from "./components/admin/changeuserinfo.vue";
import Connect from "./components/ConnectUs.vue"
import Editvideo from "./components/admin/editvideo.vue";
import Editphoto from "./components/admin/editphoto.vue";
import Login from "./components/Login.vue";
import OurWorks from "./components/OurWorks.vue";
import Photo from "./components/Photo.vue";
import Setup from "./components/admin/setup.vue";
import Video from "./components/Video.vue";
import VideoPlayer from "./components/VideoPlayer.vue";
import NotFound from "./components/NotFound.vue";
import ViewPhoto from "./components/ViewPhoto.vue";
import SubmitComplete from "./components/SubmitComplete.vue";

const routes=[
    {
        path:'/',
        redirect:'/index'
    },
    {
        path:'/index',
        component:Home
    },
    {
        path:'/about',
        component: About
    },
    {
        path:'/admin',
        component: Admin,

    },
    {
        path:'/admin/editvideo',
        component: Editvideo,

    },
    {
        path:'/admin/addvideo',
        component: Addvideo,

    },
    {
        path:'/admin/editphoto',
        component: Editphoto,

    },
    {
        path:'/admin/changeuserinfo',
        component: ChangeUserInfo,

    },{
        path:'/admin/changeuserinfo',
        component: ChangeUserInfo,

    },
    {
        path:'/admin/setup',
        component: Setup,

    },
    {
        path:"/admin/login",
        component: Login,
        name:"login"
    },
    {
        path: '/complete',
        component: SubmitComplete
    },
    {
        path: '/connectus',
        component: Connect
    },
    {
        path:'/ourworks',
        component: OurWorks
    },
    {
        path:'/photo',
        component: Photo
    },
    {
        name:'ViewPhoto',
        path:'/photo/:id',
        component: ViewPhoto
    },
    {
        path: '/video',
        component: Video,
    },
    {
        path:'/video/:id',
        name: 'VideoPlayer',
        component:VideoPlayer
    },
    {
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        component: NotFound
    }
];
export const router = createRouter({
    history: createWebHistory(),
    routes:routes
});
router.beforeEach((to,from)=>{
    const isAuthenticated=window.sessionStorage.getItem("isAuthenticated");
    if((to.path=='/admin'||to.path=='/admin/changeuserinfo'
        ||to.path=='/admin/editvideo'
        ||to.path=='/admin/editphoto')&&!isAuthenticated){
        return {name: "login"};
    }else {
        return true;
    }
})
const app=createApp(App);
app.use(router);
app.mount('#app');
